<?php
declare (strict_types = 1);

namespace app\common\model;
use app\api\model\Base;
use think\model\concern\SoftDelete;

/**
 * 评论模型
 */
class Comment extends Base
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * 获取评论详情
     */
    public static function getListAndmMemberByCourseId($course_id)
    {
        $data = self::field('id,content,member_id,create_time,reply')
                        ->with(['member'=>function($query){
                            $query->withField(['id,account,avatar']);
                        }])
                        ->where(['course_id'=>$course_id,'status'=>self::STATUS_NORMAL])
                        ->select();
        return $data ? $data->toArray() : null;
    }

    /**
     * 查询评论的用户信息
     * @return \think\model\relation\BelongsTo
     */
    public function member()
    {
        return $this->belongsTo('Member','member_id','id');
    }

    /**
     * 查询课程的评论
     * @return \think\model\relation\BelongsTo
     */
    public function course()
    {
        return $this->belongsTo('Course','course_id','id');
    }

}